1 : <?php
2 :
3 : /*--------------------------------------------------------------------------+
4 : This file is part of eStudy.
5 : news/classes/class.NewsCategoryCourses.inc.php
6 : - Modulgruppe: News
7 : - Beschreibung: Klasse für die News-Kategorie Kurse.
8 : - Version: 1.1.0, 02/28/08
9 : - Autor(en):
10 : +---------------------------------------------------------------------------+
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or any later version.
15 : +---------------------------------------------------------------------------+
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 : You should have received a copy of the GNU General Public License
21 : along with this program; if not, write to the Free Software
22 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 : +--------------------------------------------------------------------------*/
24 :
25 1 : require_once ("class.newscategory.inc.php");
26 :
27 : /**
28 : * Klasse für die News-Kategorie Kurse.
29 : * @package eStudy.News
30 : * @version 1.1.0, 02/28/08
31 : */
32 1 : class NewsCategoryEcom extends NewsCategory {
33 : /**
34 : * HTML-Template
35 : * @var Template
36 : */
37 : private $newsTemplate;
38 : /**
39 : * @var int
40 : */
41 : private $userID;
42 : /**
43 : * Konstruktor
44 : * @param $userID int
45 : */
46 : public function __construct($catID, $courses, $userID, $categorySettings = null) {
47 0 : parent :: __construct($catID, $courses, $categorySettings);
48 0 : $this->userID = $userID;
49 0 : $this->newsTemplate = new Template(PATH_TO_ROOT . "news/templates/newsecom.html");
50 0 : }
51 :
52 : /**
53 : * @see NewsCategory
54 : */
55 : public function isInstalled($courseID) {
56 0 : return (($courseID == 0) ? true : false);
57 : }
58 :
59 : /**
60 : * @see NewsCategory
61 : */
62 : public function canSelectPeriod() {
63 0 : return true;
64 : }
65 :
66 : /**
67 : * @see NewsCategory
68 : */
69 : public function getNewsHeaderTitle($courseID = null, $type = null) {
70 0 : if (isset ($this->news)) {
71 0 : $newsCount = $this->news["count"];
72 0 : if ($newsCount > 1)
73 0 : $title = sprintf( $this->translate->_("%1\$s eCommunities"), $newsCount);
74 0 : elseif ($newsCount == 1) $title = $this->translate->_("1 eCommunity");
75 0 : } else
76 0 : $title = $this->translate->_("Keine neuen eCommunities");
77 :
78 0 : return $title;
79 : }
80 :
81 : /**
82 : * @see NewsCategory
83 : */
84 : protected function getNewsByPeriod($courseID, $from, $to, $lastvisit, $usergroup = null) {
85 : // Neue Mitteilungen
86 0 : if (isset ($courseID) && isset ($lastvisit) && isset ($this->coursePreferences)) {
87 0 : if (!is_numeric($courseID) || !is_numeric($lastvisit) || !is_numeric($usergroup))
88 0 : return null;
89 :
90 0 : global $db;
91 0 : $this->news = array ();
92 :
93 0 : if (!$courseID) {
94 : $sql = "SELECT * FROM courses " .
95 0 : "WHERE OpenDate BETWEEN '" . date("Y-m-d", $this->getPeriod($courseID, $lastvisit)) . "' " .
96 0 : "AND '" . date("Y-m-d", time()) . "' " .
97 0 : "AND closed=0 " .
98 0 : "AND Type = 'ecom' " .
99 0 : "ORDER BY Opendate DESC";
100 0 : $this->news["data"] = $db->get_results($sql, ARRAY_A);
101 :
102 0 : if ($db->num_rows == 0)
103 0 : $this->news = null;
104 : else {
105 0 : $this->news["count"] = $db->num_rows;
106 : // Für jeden Kurs die UserID des Dozenten holen
107 : // Bei mehreren Dozenten wird der geholt, der den Kurs angelegt hat
108 0 : foreach ($this->news["data"] as $key => $course) {
109 : $sql = "SELECT userID FROM user_course, user " .
110 0 : "WHERE courseID='{$course['ID']}' " .
111 0 : "AND userID=user.ID " .
112 0 : "ORDER BY user_course.regtime LIMIT 1";
113 0 : $userID = $db->get_var($sql);
114 0 : $this->news["data"][$key]["userID"] = $userID;
115 : $sql = "SELECT COUNT(*) FROM user_course_wait " .
116 0 : "WHERE userID='" . Data :: toMysql($this->userID) . "' " .
117 0 : "AND courseID='{$course['ID']}'";
118 0 : $this->news["data"][$key]["waiting"] = (bool) $db->get_var($sql);
119 0 : $this->users[$userID] = $userID;
120 0 : }
121 : }
122 0 : }
123 0 : }
124 :
125 0 : return $this->news;
126 : }
127 : /**
128 : * @see NewsCategory
129 : */
130 : protected function echoNewsEntry($entry, $courseID, $usergroup = null) {
131 0 : if (!isset ($entry) || !isset ($courseID) || !isset ($this->news["user"]))
132 0 : return;
133 :
134 0 : $closed = "";
135 0 : if (strtotime($entry["CloseDate"] . " 23:59:59") < time()) {
136 : $closed = " <span style='font-weight:normal;font-style:italic'>("
137 0 : . $this->translate->_("Anmeldefrist abgelaufen")
138 0 : . ")</span>";
139 0 : }
140 0 : elseif ($usergroup == DOZENT || $usergroup == STUDENT || $usergroup == SCHUELER || $usergroup == GAST || $usergroup == ALUMNUS && isset ($this->courses) && !in_array($entry["ID"], array_keys($this->courses)) && !$entry["waiting"]) {
141 0 : $closed = " (<a href='" . PATH_TO_ROOT . "courses/register.php?courseID=$entry[ID]'>"
142 0 : . $this->translate->_("Anmelden")
143 0 : . "</a>)";
144 0 : }
145 0 : $courseName = Data :: toHTML("$entry[Name] ($entry[ShortName])", false);
146 0 : $profileLink = $this->getProfileLink($this->news["user"], $entry["userID"], $courseID);
147 0 : $courseInfo = Utilities :: chopText($entry["Info"], 150);
148 0 : $scriptPath = PATH_TO_ROOT . "courses/courseinfo.php";
149 0 : $courseID = Data :: toHTML($entry["ID"], false);
150 :
151 0 : $g_ZureCommunityInfo = $this->translate->_("Zur eCommunity-Info");
152 0 : $g_Lesen = $this->translate->_("Lesen");
153 :
154 0 : eval ($this->newsTemplate->GetTemplate());
155 0 : }
156 : }
|